package com.cote.douhahou.pretloan.any.data.akomapalendtask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.cote.douhahou.pretloan.any.data.akomapalendhttp.AkomapalendASReqstManger;
import com.cote.douhahou.pretloan.any.data.akomapalendservices.AkomapalendASDecIfo;
import com.cote.douhahou.pretloan.beans.AkomapalendASDecBn;
import com.cote.douhahou.pretloan.url.AkomapalendPaths;
import com.cote.douhahou.pretloan.utils.AkomapaLendUtil;
import com.cote.douhahou.pretloan.any.data.akomapalendlogger.AkomapalendASLger;

import java.util.function.Supplier;


public class AkomapalendASDevcTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceTask";

    private final String mTaskId;
    private final Context mContext;

    public AkomapalendASDevcTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        
        AkomapalendASLger.logd(TAG, TAG + " Processing...");

        
        if (TextUtils.isEmpty(AkomapalendPaths.PATH_DEVICE)) {
            return mTaskId + "";
        }
        AkomapalendASDecBn infoBeans;
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE)) {
            infoBeans = AkomapalendASDecIfo.dataList(mContext);
        } else {
            
            AkomapalendASLger.logd(TAG, "Fail:No  READ_PHONE_STATE Permission");
            return mTaskId + "";
        }

        String result = infoBeans.toEncrynd(AkomapalendPaths.PATH_DEVICE);

        
        String url = AkomapaLendUtil.commonUrl();
        new AkomapalendASReqstManger.Builder().stReqId(this.mTaskId).stUrl(url).seBody(result).build().doPtRqst();

        return mTaskId + "";
    }

}
